/*
 * ==========================================================================*\
 * | $Id: JavaStatementElement.java 360 2011-02-20 19:43:41Z vtwoods@gmail.com $
 * |*-------------------------------------------------------------------------*|
 * | Copyright (C) 2009 Virginia Tech | | This file is part of CloudSpace. | |
 * CloudSpace is free software; you can redistribute it and/or modify | it under
 * the terms of the GNU General Public License as published | by the Free
 * Software Foundation; either version 3 of the License, or | (at your option)
 * any later version. | | CloudSpace is distributed in the hope that it will be
 * useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of |
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | GNU General
 * Public License for more details. | | You should have received a copy of the
 * GNU General Public License | along with CloudSpace; if not, see
 * <http://www.gnu.org/licenses/>.
 * \*==========================================================================
 */

package student.web.internal;

import java.io.IOException;
import java.io.Writer;

import org.zkoss.zhtml.Text;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.metainfo.LanguageDefinition;
import org.zkoss.zk.ui.sys.ComponentsCtrl;


// -------------------------------------------------------------------------
/**
 * A base class for creating simple ZK components that represent Java-style
 * statements.
 * 
 * @author Stephen Edwards
 * @author Last changed by $Author: vtwoods@gmail.com $
 * @version $Revision: 360 $, $Date: 2010-11-17 22:10:44 -0500 (Wed, 17 Nov
 *          2010) $
 */
public class JavaStatementElement extends Text
// extends AbstractComponent
{
    // ~ Constructors ..........................................................

    /**
	 * 
	 */
    private static final long serialVersionUID = -3587976629182820042L;


    // ----------------------------------------------------------
    /**
     * Creates a new object.
     */
    public JavaStatementElement()
    {
        super();
        setVisible( false );
    }


    // ~ Methods ...............................................................

    // // ----------------------------------------------------------
    // public boolean isChildable()
    // {
    // return false;
    // }
    //
    // // ----------------------------------------------------------
    // public void redraw(Writer out)
    // throws IOException
    // {
    // super.redraw(out);
    // }
    public void redraw( Writer out ) throws IOException
    {
        if ( isIdRequired() )
            super.redraw( out );
    }


    protected boolean isIdRequired()
    {
        final Component p = getParent();
        return p == null || !isVisible()
            || !ComponentsCtrl.isAutoUuid( getId() ) || !isRawLabel( p );
    }


    protected static boolean isRawLabel( Component comp )
    {
        final LanguageDefinition langdef = comp.getDefinition()
            .getLanguageDefinition();
        return langdef != null && langdef.isRawLabel();
    }
}
